package com.lock.immersive.controller;

import com.lock.immersive.annotation.AuthCheck;
import com.lock.immersive.exception.BusinessException;
import com.lock.immersive.mapper.CouponMapper;
import com.lock.immersive.pojo.dto.CouponDto;
import com.lock.immersive.service.CouponService;
import com.lock.immersive.utils.ErrorCode;
import com.lock.immersive.utils.ResponseApi;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;


@RestController
@RequestMapping("/coupon")
public class CouponController {
    @Resource
    public CouponService couponService;
    @Resource
    public CouponMapper couponMapper;

    @PostMapping("/insertCoupon")
    @AuthCheck(mustRole = "superManager")
    public ResponseApi<Object> insertCoupon(@RequestBody CouponDto couponDto) throws Exception {
        return couponService.insertCoupon(couponDto);
    }

    @PostMapping("/deleteCouponList")
    @AuthCheck
    public ResponseApi<Object> deleteCoupon(@RequestBody List<String> ids) {
        int i = couponMapper.deleteBatchIds(ids);
        if (i > 0) {
            return ResponseApi.success("删除成功");
        } else {
            throw new BusinessException(ErrorCode.OPERATION_ERROR);
        }
    }
}
